home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / BackSpaceModules / Source / BattleView / SpaceThing.m < prev    next >
Text File  |  1994-05-04  |  2KB  |  116 lines

  1. /* SpaceThing.m -- implementation for SpaceThing objects
  2.    Copyright (C) 1992, 1993 David A. Strout
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Written by David Strout <dstrout@isi.edu>. */
  19.  
  20.  
  21. #import "SpaceThing.h"
  22. #import "Thinker.h"
  23. #import <appkit/NXImage.h>
  24.  
  25.  
  26. @implementation SpaceThing
  27.  
  28. - findImageNamed:(const char *)name
  29. /* Loads the tiff 'name' into a newly alloc'd NXImage and returns that image's id */
  30. {
  31.   char buf[1024];
  32.   id ret = [NXImage findImageNamed:name];
  33.   if (ret) return ret;
  34.   sprintf(buf,"%s/%s.tiff",[[NXApp delegate] moduleDirectory:"Battle"],name);
  35.   ret = [[NXImage alloc] initFromFile:buf];
  36.   [(NXImage *)ret setName:name];
  37.   return ret;
  38. }
  39.  
  40. - init
  41. /* Unless someone tells us otherwise, assume we're on a full screen */
  42. {
  43.   if(!maxX) maxX=1120;
  44.   if(!maxY) maxY=832;
  45.   [super init];
  46.   return self;
  47. }
  48.  
  49. - setViewXSize:(float)x YSize:(float)y
  50. {
  51.   maxX=x;maxY=y;
  52.   [self checkMove];
  53.   return self;
  54. }
  55.  
  56. - drawSelf
  57. /* This should be over-ridden in subclasses */
  58. {
  59.   
  60.   return self;
  61. }
  62.  
  63. - oneStep
  64. /* This is called by BattleView's oneStep method, not by BackSpace directly */
  65. {
  66.   if(ONEIN(NEW_HEAD)) [self newVector];
  67.   [self checkMove];
  68.   [self drawSelf];
  69.   return self;
  70. }
  71.  
  72. - newVector
  73. {
  74.   heading=RANDINT(7);
  75.   speed=RANDINT(5)+2;    
  76.   return self;
  77. }
  78.  
  79. - checkMove
  80. /* If we have gone beyond the edge of the view, move back to the edge and pick a new vector */
  81. {
  82.   if(location.x>maxX) {
  83.     location.x=maxX;
  84.     [self newVector];
  85.   };
  86.   
  87.   if(location.x<0) {
  88.     location.x=0;
  89.     [self newVector];
  90.   };
  91.   
  92.   if(location.y>maxY) {
  93.     location.y=maxY;
  94.     [self newVector];
  95.   };
  96.   
  97.   if(location.y<0) {
  98.     location.y=0;
  99.     [self newVector];
  100.   };
  101.   
  102.   return self;
  103. }
  104.  
  105. - (float) xLoc
  106. {
  107.   return location.x;
  108. }
  109.  
  110. - (float) yLoc
  111. {
  112.   return location.y;
  113. }
  114.  
  115. @end
  116.